﻿using System;
using System.Collections.Generic;
using System.Text;

namespace WcfServiceBomberman.MatchMaking
{
    public class Player : IComparable<Player>
    {
        const int max_seconds = 120;
        const int elo_per_second = 2;
        public uint elo;
        public Contracts.Duplex.Player player;
        public DateTime time;

        public Player(Contracts.Duplex.Player player, uint elo)
        {
            this.player = player;
            this.elo = elo;
            time = DateTime.Now;
        }

        public bool willAccept(Player other, int elapsed)
        {
            int range = elapsed * elo_per_second;
            return ((other.elo < (elo + range)) && (other.elo > (elo - range)));
        }

        public bool willForce(int elapsed)
        {
            return elapsed > max_seconds ;
        }

        public int elapsed(DateTime time)
        {
            return (time - this.time).Seconds;
        }

        public int CompareTo(Player other)
        {
            if (elo > other.elo)
                return 1;
            if (elo < other.elo)
                return -1;
            else
                return 0;
        }

        public uint range(Player other)
        {
            return (uint)Math.Abs(elo - other.elo);
        }
    }
}
